package com.google.code.p.fop_qrcode;

import java.awt.geom.Point2D;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationUtil;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.util.UnitConv;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;

public class QRCodeElement extends QRCodeObj {
    public QRCodeElement(FONode parent) {
        super(parent);
    }
    
    public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList propertyList)
            throws FOPException {
        super.processNode(elementName, locator, attlist, propertyList);
        createBasicDocument();
    }
    
    public Point2D getDimension(Point2D view) {
        Configuration cfg = ConfigurationUtil.toConfiguration(this.doc.getDocumentElement());
        float length = cfg.getAttributeAsFloat("length", QRCodeXMLHandler.DEFAULT_LENGTH);
        return new Point2D.Float((int)UnitConv.mm2pt(length), (int)UnitConv.mm2pt(length));
    }
}
